package com.lei.app.processor;

import org.nutz.lang.Strings;
import org.nutz.lang.Times;
import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionInfo;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.NutConfig;
import org.nutz.mvc.impl.processor.AbstractProcessor;

/**
 * @author liujianguo
 * @data 2020/1/2
 * 描述：
 */
public class GlobalsSettingProcessor extends AbstractProcessor {

    @Override
    public void init(NutConfig config, ActionInfo ai) throws Throwable {
    }

    @SuppressWarnings("rawtypes")
    @Override
    public void process(ActionContext ac) throws Throwable {
        ac.getRequest().setAttribute("AppName", "WebSocket 在线测试");
        ac.getRequest().setAttribute("version", Times.getTS());
        // 如果url中有语言属性则设置
        String lang = ac.getRequest().getParameter("lang");
        if (!Strings.isEmpty(lang)) {
            Mvcs.setLocalizationKey(lang);
        } else {
            // Mvcs.getLocalizationKey()  1.r.56 版本是null,所以要做两次判断, 1.r.57已修复为默认值 Nutz:Fix issue 1072
            lang = Strings.isBlank(Mvcs.getLocalizationKey()) ? Mvcs.getDefaultLocalizationKey() : Mvcs.getLocalizationKey();
        }
        ac.getRequest().setAttribute("lang", lang);
        doNext(ac);
    }
}